package com.funong.matrix.biz.massage.facade.impl;

import com.alibaba.fastjson.JSONObject;
import com.funong.matrix.biz.base.dao.SysSendTaskDao;
import com.funong.matrix.biz.base.entity.SysSendTaskEntity;
import com.funong.matrix.biz.massage.facade.SysSendTaskFacade;
import com.funong.matrix.biz.massage.pojo.MessageInfoDTO;
import com.funong.matrix.biz.massage.pojo.WebsocketInMailDTO;
import com.funong.matrix.core.config.websocket.WebSocketServer;
import com.funong.matrix.core.dto.QueryDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : NaNa
 * @since : 2023-05-19 17:01
 **/
@Slf4j
@Service
public class SysSendTaskFacadeImpl implements SysSendTaskFacade {

    @Resource
    private SysSendTaskDao sysSendTaskDao;

    @Override
    public void save(SysSendTaskEntity sendTaskEntity) {
        sysSendTaskDao.save(sendTaskEntity);
    }

    @Override
    public boolean isSendSuccess(String bizId) {
        return false;
    }

    @Override
    public List<SysSendTaskEntity> querySendTaskEntity(QueryDTO<SysSendTaskEntity> queryDTO) {
        return null;
    }

    @Override
    public void pushWebsocketMsg(Integer userId, Object object) {
        try {
            WebSocketServer.broadCastInfo(String.valueOf(userId), object);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("websocket推送失败：{}", JSONObject.toJSONString(e));
        }
    }

    @Override
    public void pushWebsocketInMailMsg(WebsocketInMailDTO websocketInMailDTO) {
        try {
            WebSocketServer.broadCastInfo(String.valueOf(websocketInMailDTO.getUserId()), websocketInMailDTO);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("websocket推送失败：{}", JSONObject.toJSONString(e));
        }
    }
}
